package thread;

public class Demo4 {
    public static void main(String[] args) {
        // 使用匿名内部类实现Runnable接口
        Runnable myRunnable = new Runnable() {
            @Override
            public void run() {
                // 线程执行的代码
                for (int i = 1; i <= 5; i++) {
                    System.out.println("匿名内部类线程执行: " + i);
                    try {
                        Thread.sleep(500); // 休眠0.5秒
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
    
        // 创建线程并启动
        Thread thread = new Thread(myRunnable);
        thread.start();
        
        while (true) {
            
            System.out.println("main");
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        }

    
    }
}

